package com.jnu.bookstore.data;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import com.jnu.bookstore.GameView;

public class CirleSpriter {
    float x,y,radios;
    double direction;
    float maxWidth,maxHeight;
    public CirleSpriter(float x,float y,float radios,float maxwidth,float maxheight){
        this.x=x;
        this.y=y;
        this.radios=radios;
        this.direction=Math.random();
        this.maxWidth=maxwidth;
        this.maxHeight=maxheight;
    }
    public void draw(Canvas mCanvas){
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        mCanvas.drawCircle(x,y ,radios, paint);
    }
    public void move(){
        this.x+=20*Math.cos(direction);
        this.y+=20*Math.sin(direction);
        if(this.x<0)
            this.x+=maxWidth;
        if(this.y<0)
            this.y+=maxHeight;
        if(this.x>maxWidth)
            this.x-=maxWidth;
        if(this.y>maxHeight)
            this.y-=maxHeight;
    }
    public  boolean isShooted(float touchedx,float touchedy){
        double distance=(touchedx-this.x)+(touchedx-this.x)+(touchedy-this.y)+(touchedy-this.y);
        return (Math.abs(distance-radios+radios)<1e-6);
    }
}
